<template>
  <view>
    <!-- <my-search :bgcolor="'black'"></my-search> -->
   <view class="search-absolute">
      <my-search></my-search>
   </view>
    <!-- 轮播图 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="(item,i) in swiperlist" :key="i">
        <navigator class="swiper-item" :url="'../../subpkg/good_detail/good_detail?goods_id='+item.goods_id">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- nav导航栏 -->
    <view class="nav">
      <view class="nav-item" v-for="(item,index) in navlist" :key="index" @click="navclickhandle(item)">
        <image :src="item.image_src"></image>
      </view>
    </view>
    <!-- 楼层区 -->
    <view class="floor-list">
      <view class="floor-item" v-for="(item,i) in floorlist" :key="i">
        <!-- 标题渲染 -->
        <image :src="item.floor_title.image_src" class="floor-title"></image>
        <view class="floor-img-box">
          <!-- 左侧图片区域 -->
          <navigator class="left-img-box" :url="item.product_list[0].url">
            <img :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}"
              mode="widthFix">
          </navigator>
          <!-- 右侧图片区域 -->
          <view class="right-img-box">
          <navigator :url="item2.url" class="right-img-item" v-for="(item2,i2) in item.product_list" :key="i2" v-if="i2!='0'">
              <img :src="item2.image_src" :style="{width:item2.image_width +'rpx'}" mode="widthFix">
            </navigator>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import badgeMix from '@/mixin/tabbar-badge.js'
  export default {
    mixins:[badgeMix],
    data() {
      return {
        swiperlist: [],
        navlist: [],
        floorlist: []
      };
    },
    onLoad() {
      this.getSwiperList(),
        this.getNavList(),
        this.getFloorlist()
    },
    methods: {
      async getSwiperList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        if (res.meta.status !== 200) return uni.$showMsg()
        this.swiperlist = res.message
      },
      async getNavList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/catitems')
        if (res.meta.status !== 200) return uni.$showMsg()
        this.navlist = res.message
      },
      async getFloorlist() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/floordata')
        if (res.meta.status !== 200) return uni.$showMsg()
        res.message.forEach(floor=>{
          floor.product_list.forEach(pro=>{
            pro.url="/subpkg/goods_list/goods_list?"+pro.navigator_url.split("?")[1]
          })
        })
        this.floorlist = res.message
      },
      navclickhandle(item) {
        if (item.name == "分类") {
          wx.switchTab({
            url: "/pages/cate/cate"
          })
        }
      },
      // gotoSearch(){
      //   console.log(123);
      //   uni.navigateTo({
      //     url:"/subpkg/search/search"
      //   })
      // }
    }
  }
</script>

<style lang="scss">
  swiper {
    height: 300rpx;

    .swiper-item,
    image {
      width: 100%;
      height: 100%;
    }
  }
.search-absolute{
  position: sticky;
  top: 0;
  z-index: 999;
}
  .nav {
    display: flex;
    justify-content: space-around;
    margin: 15px 0;

    image {
      width: 128rpx;
      height: 140rpx;
    }
  }

  .floor-title {
    width: 100%;
    height: 60rpx;
  }

  .right-img-box {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
  }

  .floor-img-box {
    display: flex;
    padding-left: 10rpx;
  }
</style>
